package redtankface.tasks;

import redtankface.*;

abstract public class AbstractTankChooseTask extends TankTask {

	protected EnemyInfo bestEnemy = null;

    public AbstractTankChooseTask(RedTankFace aRobot) {
        super(aRobot);
    }

    protected abstract long getLocalRating(EnemyInfo aEnemy, double distance, double heading);

    @Override
	public final long getRating() {
		bestEnemy = null;
		long rating = 0;
		for (EnemyInfo enemy : mRobot.getEnemies().values()) {

			TankCoordinates myPos = mRobot.getCoord();
			TankCoordinates enPos =  enemy.getCoord(mRobot.getTime());
			double heading = TankUtils.getAngle(myPos, enPos);
			double distance = TankUtils.getDistance(myPos, enPos);

			long tek = getLocalRating(enemy, distance, heading);
			if (rating == 0 || tek > rating) {
				rating = tek;
				bestEnemy = enemy;
			}
		}
		return rating;
	}
}
